package com.qf.anno.web.exhandlers;

import com.qf.anno.domain.Code;
import com.qf.anno.domain.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R ex(Exception e){
        e.printStackTrace();

        return R.error("服务器忙，稍后重试！");
    }

    @ExceptionHandler(BussinessException.class)
    public R bEx(BussinessException bex){
        bex.printStackTrace();

        int code = bex.getCode();
        if (code == Code.ACCOUNT_NOT_EXISTS){
            return R.error("转入账户不存在");
        }

        if (code == Code.ACCOUNT_MONEY_NOT_ENOUGH){
            return R.error("余额不足");
        }

        return R.error(code + "");
    }
}
